<?php


class XephangHelper extends AppHelper {
   var $helpers = array('Html','Others');
    
    /** ********************************************************************************
     * showall: showing all statistics about selling products of brands
     * Hien thi cac chi nhanh, co xep hang 
     * (only used for luyke of chinhhanh, because of aiming to run faster and saving memory)
     * 
     * @param $data         Du lieu hien thi                    array
     * @param $datarank     Du lieu dung de ho tro xep hang     array
     * @param $cot          Tieu de cot                         array
     * @param $dong         Tieu de dong                        array
     * 
     * @return  HTML
     * ********************************************************************************/	
       
  function showall($data,$datarank,$cot,$dong,$border=0){
    $n=count($cot);
    $m=count($dong);
    
    $generalrank=array();
    
    
    $kq='<table id="tables" border="'.$border.'">';  
    //for($i=-1;$i<$m;$i++){
    
    $kq=$kq. '<th rowspan="2">TT</th>';
    $kq=$kq. '<th rowspan="2">Sản phẩm</th>';
    $kq=$kq. '<th rowspan="2">Điểm chuẩn</th>';
    
               
  //so nhom la 4          
    foreach($cot as $c):
        $kq=$kq. '<th colspan="4"><b><font color="#0136C7">'.
                      $c.'</font></b></th>';
    
                  
   endforeach;
   $kq.='<tr>'; 
   for($i=0;$i<$n;$i++){
        $kq=$kq. '<th><b><font color="#B601C7">Lũy kế</font></b></th>';
        $kq=$kq. '<th><b><font color="#B601C7">KH</font></b></th>';
        $kq=$kq. '<th><b><font color="#B601C7">%</font></b></th>';
        $kq=$kq. '<th><b><font color="#B601C7">Xếp thứ</font></b></th>';
        //khoi tao mang de lat cong vo
        $generalrank[$i]=0;
  
   }
   $kq.='</tr>'; 
    $i=0;   
    foreach ($dong as $key=>$d):
       
        $kq.='<tr>';
        
            $kq.='<td>'.($i+1).'</td>';
            $kq.='<td>'.$key.'</td><td>'.$d.'</td>';
            for($j=0;$j<$n;$j++){//chay theo so cot, moi j la 1 donvi
                               
                  $generalrank[($j%$n)]+=($d*$data[$n*($i)+$j]['Zdvluyke1']['tyle']);
                  $kq=$kq. '<td>'.$data[$n*($i)+$j]['Zdvluyke1']['kqban_n'].'</td>';
                  $kq=$kq. '<td>'.$data[$n*($i)+$j]['Zdvluyke1']['chitieu_n'].'</td>';
                 
                  $kq=$kq. '<td>'.(100*$data[$n*($i)+$j]['Zdvluyke1']['tyle']).'%</td>';
                  $kq=$kq. '<td>'.$this->Others->rank_value($data[$n*($i)+$j]['Zdvluyke1']['tyle'],$datarank[$i]).'</td>';
            }
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
     $kq.='<tr><th colspan="3">Đánh giá chung</th>';
      for($i=0;$i<$n;$i++){
        $kq=$kq. '<th><b><font color="#1C0909">Điểm</font></b></th>';
        $kq=$kq. '<th><b><font color="#3300CC"><strong>'.$generalrank[$i].'</strong></font></b></th>';
        $kq=$kq. '<th><b><font color="#1C0909">Xếp thứ</font></b></th>';
        $kq=$kq. '<th><b><font color="#3300CC">'.$this->Others->rank_value($generalrank[$i],$generalrank).'</font></b></th>';
        //khoi tao mang de lat cong vo
        
  
        }
        $kq.='</tr>';
     
     
    //}
  //  print_r($generalrank);
    
    $kq.='</table>';
    
    return $kq;
    
    
  }

    function showalle($data,$datarank,$cot,$dong,$border=1,$mau='e5e5e5'){
    $n=count($cot);
    $m=count($dong);
    
    $generalrank=array();
    
    
    $kq='<table border="'.$border.'">';  
    //for($i=-1;$i<$m;$i++){
    
    $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" rowspan="2">TT</th>';
    $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" rowspan="2">Sản phẩm</th>';
    $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold"  rowspan="2">Điểm chuẩn</th>';
    
               
  //so nhom la 4          
    foreach($cot as $c):
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold" colspan="4"><b><font color="#0136C7">'.
                      $c.'</font></b></th>';
    
                  
   endforeach;
   $kq.='<tr>'; 
   for($i=0;$i<$n;$i++){
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold"><b><font color="#B601C7">Lũy kế</font></b></th>';
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold"><b><font color="#B601C7">KH</font></b></th>';
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold"><b><font color="#B601C7">%</font></b></th>';
        $kq=$kq. '<th style="background: #'.$mau.'; font-weight: bold"><b><font color="#B601C7">Xếp thứ</font></b></th>';
        //khoi tao mang de lat cong vo
        $generalrank[$i]=0;
  
   }
   $kq.='</tr>'; 
    $i=0;   
    foreach ($dong as $key=>$d):
       
        $kq.='<tr>';
        
            $kq.='<td>'.($i+1).'</td>';
            $kq.='<td>'.$key.'</td><td>'.$d.'</td>';
            for($j=0;$j<$n;$j++){//chay theo so cot, moi j la 1 donvi
                               
                  $generalrank[($j%$n)]+=($d*$data[$n*($i)+$j]['Zdvluyke1']['tyle']);
                  $kq=$kq. '<td>'.$data[$n*($i)+$j]['Zdvluyke1']['kqban_n'].'</td>';
                  $kq=$kq. '<td>'.$data[$n*($i)+$j]['Zdvluyke1']['chitieu_n'].'</td>';
                 
                  $kq=$kq. '<td>'.(100*$data[$n*($i)+$j]['Zdvluyke1']['tyle']).'%</td>';
                  $kq=$kq. '<td>'.$this->Others->rank_value($data[$n*($i)+$j]['Zdvluyke1']['tyle'],$datarank[$i]).'</td>';
            }
        $kq.='</tr>';
        
        $i++;
        
     endforeach;  
     $kq.='<tr><th colspan="3">Đánh giá chung</th>';
      for($i=0;$i<$n;$i++){
        $kq=$kq. '<th><b><font color="#1C0909">Điểm</font></b></th>';
        $kq=$kq. '<th><b><font color="#3300CC"><strong>'.$generalrank[$i].'</strong></font></b></th>';
        $kq=$kq. '<th><b><font color="#1C0909">Xếp thứ</font></b></th>';
        $kq=$kq. '<th><b><font color="#3300CC">'.$this->Others->rank_value($generalrank[$i],$generalrank).'</font></b></th>';
        //khoi tao mang de lat cong vo
        
  
        }
        $kq.='</tr>';
     
     
    //}
  //  print_r($generalrank);
    
    $kq.='</table>';
    
    return $kq;
    
    
  }


}
 ?>